<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <link rel="stylesheet" href="http://120.46.82.82:8080/code/static/layui/css/layui.css"/>
    <link rel="stylesheet" href="http://120.46.82.82:8080/code/static/fsLayui/plugins/jquery/jquery.min.js"/>

    <!--绝对路径：D:\Springboot_Java\code\src\main\resources\static\static\fsLayui\plugins\jquery\jquery.min.js-->
    <!--http://120.46.82.82:8080/code/+-->
    <!--static/static/layui/layui.js-->
    <!--${pageContent.request.ContentPath}-->
</head>
<body style="height: 300px">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px">
    <legend class="">用户注册</legend>
</fieldset>

<form class="layui-form" action="/code" method="post" style="text-align: center">
    <div class="layui-form-item" style="margin-bottom: 5px">
        <label class="layui-form-label">用&nbsp;户&nbsp;名：</label>
        <div class="layui-input-inline">
            <input type="text" lay-verify="userName" name="userName" required="true" placeholder="请输入用户名" autocomplete="off"
                   class="layui-input"
                   style="width: 280px"/>
        </div>
    </div>

    <div class="layui-form-item" style="margin-bottom: 5px">
        <label class="layui-form-label">密&nbsp;&nbsp;码：</label>
        <div class="layui-input-inline">
            <input type="password" lay-verify="password" name="password" required="true" placeholder="请输入密码" autocomplete="off"
                   class="layui-input"
                   style="width: 280px"/>
        </div>
    </div>
    <div class="layui-form-item" style="margin-bottom: 5px">
        <label class="layui-form-label">昵&nbsp;&nbsp;称：</label>
        <div class="layui-input-inline">
            <input type="text" lay-verify="nickname" name="nickname" required="true" placeholder="请输入昵称" autocomplete="off"
                   class="layui-input"
                   style="width: 280px"/>
        </div>
    </div>
    <div class="layui-form-item" style="margin-bottom: 5px">
        <label class="layui-form-label">邮&nbsp;&nbsp;箱：</label>
        <div class="layui-input-inline">
            <input type="email" name="email" required="true" placeholder="请输入邮箱（用于找回密码）" autocomplete="off"
                   class="layui-input"
                   style="width: 280px"/>
        </div>
    </div>
    <div class="layui-form-item" style="margin-bottom: 5px;text-align: left;">
        <label class="layui-form-label">性&nbsp;&nbsp;别：</label>
        <input type="radio" name="sex" value="男" title="男" checked />
        <input type="radio" name="sex" value="女" title="女"/>
    </div>

    <div class="layui-form-item" style="margin-top: 15px;text-align: center;" >
        <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="checkForm" style="width: 120px">注册</button>
    </div>

</form>
<script type="text/javascript" src="http://120.46.82.82:8080/code/static/layui/layui.all.js"></script>
<!--http://120.46.82.82:8080/code/ -->
<!--<script type="text/javascript" src="../static/layui/layui.js"></script>-->
<script type="text/javascript">
    layui.form.verify({
        userName:[
            /^[\S]{5,15}$/,
            "用户名必须5-15位，且不能有空格"
        ],
        password:[
            /^[\S]{6,18}$/,
            "密码必须5-15位，且不能有空格"
        ],
        nickname:[
            /^[\S]{5,15}$/,
            "昵称必须5-15位，且不能有空格"
        ]


    });
    /*
    http://120.46.82.82:8080/code/user/register
    */
    layui.use(['form','jquery'],function(){
        var $ = layui.$;
        var form = layui.form;
        //刷新界面 所有元素
        form.render();
        form.on('submit(checkForm)',function(data){
            var data = $('form').serializeArray();
            var url = "http://120.46.82.82:8080/code/user/register"
            $.ajax({
                type: 'POST',
                url: url,
                data:data,
                async:false,
                success:function (res) {
                    if (res.success) {
                        layer.msg("注册成功",{
                            icon:1,
                            time:1500
                        },function () {
                            //do something
                            console.log(5555)
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                        parent.location.reload();
                    }else {
                        layer.msg(res.errorInfo);
                    }
                },
                error:function (data) {
                    layer.msg("网络错误！");
                }
            });
            return false;
        })

    });
</script>
</body>
</html>